<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page pageEncoding="UTF-8" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>Orders</title>
    <meta charset="UTF-8"/>
    <script type="text/javascript" src="jquery-1.6.min.js"></script>
    <LINK REL=StyleSheet HREF="admin-style.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
<section id="container" class="round">
<div id="header">
    <img id="logo" src="logo.jpg"/>
</div>
<nav>
    <a class="round" href="showOrder?mode=0">Все заказы</a> 
    <a class="round" href="showOrder?mode=2">Новые заказы</a> 
    <a class="round" href="showOrder?mode=1">Выполненные заказы</a>
</nav>
<table class="round" id="list-table">
    <tbody>
    <c:forEach var="order" items="${requestScope.orders}">
        <tr>
            <td><strong>Номер заказа:</strong> ${order.id}</td>
            <td><strong>Время заказа:</strong> ${order.time}</td>
            <td><strong>Готовность заказа:</strong> ${order.confirmed}</td>
        </tr>
        <tr>
            <td colspan="3"><a href="showOrder?mode=3&order_id=${order.id}">Чек</a></td>
        </tr>
        <tr>
            <td colspan="3" class="order-table-container">
                <table class="order-table">
                    <thead>
                    <tr>
                        <th>Название</th>
                        <th>Стоимость</th>
                        <th>Доступно</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="orderedDish" items="${order.orderedDishes}">
                        <tr>
                            <td>${orderedDish.dish.name}</td>
                            <td>${orderedDish.dish.price}</td>
                            <td>${orderedDish.dish.available}</td>
                            <td>
                                <form action="editOrder" method="post" accept-charset="utf-8">
                                    <input type="hidden" name="orderId" value="${order.id}"/>
                                    <input type="hidden" name="dishId" value="${orderedDish.dish.id}"/>
                                    <table>
                                        <tr>
                                            <td><input type="text" name="amount" value="${orderedDish.amount}"/></td>
                                            <td><input type="submit" name="deleteDish" value="Удалить блюдо из заказа"/></td>
                                        </tr>
                                    </table>
                                </form>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <form action="editOrder" method="post" accept-charset="utf-8" class="edit-order-form">
                    <input type="hidden" name="orderId" value="${order.id}"/>
                    <c:choose>
                        <c:when test="${order.confirmed == false}">
                            <input type="hidden" name="confirmStatus" value="true"/>
                            <input type="submit" name="confirm" value="Заказ выполнен"/>
                        </c:when>
                        <c:otherwise>
                            <input type="hidden" name="confirmStatus" value="false"/>
                            <input type="submit" name="confirm" value="Заказ не выполнен"/>
                        </c:otherwise>
                    </c:choose>
                </form>
                <form action="editOrder" method="post" accept-charset="utf-8" class="edit-order-form">
                    <input type="hidden" name="orderId" value="${order.id}"/>
                    <input type="submit" name="delete" value="Удалить заказ"/>
                </form>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <!-- here was a form -->
            </td>
            <td>
                <!-- here was a form -->
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</section>
</body>
</html>
